
import { _decorator, Component, Node,director,Vec2,view } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = GameInt
 * DateTime = Wed Apr 20 2022 21:55:04 GMT+0800 (中国标准时间)
 * Author = xiaopang125
 * FileBasename = GameInt.ts
 * FileBasenameNoExtension = GameInt
 * URL = db://assets/GameInt.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('GameInt')
export class GameInt extends Component {
    // [1]
    // dummy = '';

    // [2]
    @property({type:Node})
    Hero:Node = null;

    start () {
        this.node.on(Node.EventType.TOUCH_START, this.TouchStart, this)
        this.node.on(Node.EventType.TOUCH_MOVE, this.TouchMove, this)
    }
    private TouchStart(e) {
        const pos = e.getUILocation();
        
        // console.log(pos);
        // console.log(this.PosToCenter(pos));
        // console.log(this.node.position.x);
       const pos2=this.Hero.position;


    //    this.Hero.setPosition(pos.x,pos.y);
        
      
    }
    private TouchMove(e){
        var pos = e.getUILocation();
    
        // pos=this.PosToCenter(pos);
        // console.log(view.getVisibleSize());
        // console.log(this.node.position.x);
        if(pos.x>view.getVisibleSize().width / 2){
            console.log("转向右");
            
            this.Hero.setRotation(0,1,0,0);
        }else{
            console.log("转向左");
            this.Hero.setRotation(0,0,0,0);
        }
      
    }
    PosToCenter(nodePoint: Vec2){

        nodePoint.x =nodePoint.x- view.getVisibleSize().width / 2;
        nodePoint.y = nodePoint.y-view.getVisibleSize().height / 2;
        return nodePoint;
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
